package org.eiahe.hr.performance.controller;

import lombok.RequiredArgsConstructor;
import org.ehe.common.core.BaseController;
import org.eiahe.hr.performance.domain.PerformanceRewardPunish;
import org.eiahe.hr.performance.domain.bo.PerformanceRewardPunishBo;
import org.eiahe.hr.performance.domain.vo.PerformanceRewardPunishVo;
import org.eiahe.hr.performance.service.IPerformanceRewardPunishService;
import org.ehe.common.core.domain.R;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.ehe.common.mybatis.core.page.PageQuery;
import org.ehe.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.dev33.satoken.annotation.SaCheckPermission;

import java.util.List;

/**
 * 奖惩记录Controller
 *
 * @author zhangnn
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/performance/rewardPunish")
public class PerformanceRewardPunishController extends BaseController {

    private final IPerformanceRewardPunishService performanceRewardPunishService;

    /**
     * 查询奖惩记录列表
     */
    @SaCheckPermission("performance:rewardPunish:list")
    @GetMapping("/list")
    public TableDataInfo<PerformanceRewardPunishVo> list(PerformanceRewardPunishBo record, PageQuery pageQuery) {
        return performanceRewardPunishService.queryPageListVo(record, pageQuery);
    }

    /**
     * 获取奖惩记录详细信息
     */
    @SaCheckPermission("performance:rewardPunish:query")
    @GetMapping(value = "/{recordId}")
    public R<PerformanceRewardPunishVo> getInfo(@PathVariable("recordId") Long recordId) {
        return R.ok(performanceRewardPunishService.queryById(recordId));
    }

    /**
     * 新增奖惩记录
     */
    @SaCheckPermission("performance:rewardPunish:add")
    @Log(title = "奖惩记录", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody PerformanceRewardPunishBo record) {
        return toAjax(performanceRewardPunishService.insertByBo(record));
    }

    /**
     * 修改奖惩记录
     */
    @SaCheckPermission("performance:rewardPunish:edit")
    @Log(title = "奖惩记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody PerformanceRewardPunishBo record) {
        return toAjax(performanceRewardPunishService.updateByBo(record));
    }

    /**
     * 删除奖惩记录
     */
    @SaCheckPermission("performance:rewardPunish:remove")
    @Log(title = "奖惩记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public R<Void> remove(@PathVariable Long[] recordIds) {
        return toAjax(performanceRewardPunishService.deleteWithValidByIds(List.of(recordIds), true));
    }
}